package edu.xkd.slice;

import edu.xkd.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Image;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MainAbilitySlice extends AbilitySlice {
    List<Integer> lists = null;
    Image image_01 = null;
    Button button_01 = null;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        lists = new ArrayList<>();
        lists.add(ResourceTable.Media_image1);
        lists.add(ResourceTable.Media_image2);
        lists.add(ResourceTable.Media_image3);

        image_01 = (Image)this.findComponentById(ResourceTable.Id_image_01);
        button_01 = (Button)this.findComponentById(ResourceTable.Id_button_01);

        button_01.setClickedListener(this::onClickedListenerButton01);

    }
    private void onClickedListenerButton01(Component component) {
        int len = lists.size();
        Random random = new Random();

        int curIndex = lists.get(random.nextInt(len));
        image_01.setImageAndDecodeBounds(curIndex);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
